import 'dart:ffi';
import 'dart:convert';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:github_client_app/page/assets/assets_detail_page.dart';
import 'package:github_client_app/page/assets/assets_page.dart';
import 'package:github_client_app/page/assets/login_page.dart';
import 'package:github_client_app/page/assets/params_page.dart';
import 'package:github_client_app/page/assets/person.dart';
import 'package:github_client_app/page/home/ae_page.dart';
import 'package:github_client_app/page/home/book_page.dart';
import 'package:github_client_app/page/home/breathe_page.dart';
import 'package:github_client_app/page/home/db_page.dart';
import 'package:github_client_app/page/home/game_page.dart';
import 'package:github_client_app/page/home/home1_page.dart';
import 'package:github_client_app/page/home/key_game.dart';
import 'package:github_client_app/page/home/num_animate.dart';
import 'package:github_client_app/page/home/p5_page.dart';
import 'package:github_client_app/page/home/rotate_page.dart';
import 'package:github_client_app/page/home/snow_page.dart';
import 'package:github_client_app/page/home/test_page.dart';
import 'package:github_client_app/page/index_page.dart';

class Routes {
  static FluroRouter router = FluroRouter();
  static String homePage = "/";
  static String detailPage = "/detail";
  static String loginPage = "/login/:id";
  static String paramsPage = "/params";
  static String home1 = "/home1";
  static String game = "/game";
  static String keyPage = "/keypage";
  static String book = "/book";
  static String numCounter = "/num";
  static String testPage = "/test";
  static String rotatePage = "/rotatePage";
  static String breathePage = "/breathePage";
  static String snowPage = "/snowPage";
  static String dbpage = "/dbpage";
  static String p5Page = "/p5Page";
  static String aePage = "/aePage";

  static _initRouter() {
    // 首页
    router.define(homePage,
        handler: Handler(handlerFunc: (_, __) => const IndexPage()));
    // 详情页
    router.define(detailPage,
        handler: Handler(handlerFunc: (_, __) => const AssetsDetailPage()));
    // 登陆参数
    router.define(loginPage, handler: Handler(handlerFunc: (_, params) {
      String id = params['id']?.first ?? '0';
      return LoginPage(id: id);
    }));
    // 传递参数页面
    router.define(paramsPage, handler: Handler(handlerFunc: (context, params) {
      return ParamsPage();
    }));
    // home1页面
    router.define(home1, handler: Handler(handlerFunc: (context, params) {
      return Home1Page();
    }));
    // 数字小游戏
    router.define(game, handler: Handler(handlerFunc: (context, params) {
      return GamePage();
    }));
    // key小游戏
    router.define(keyPage, handler: Handler(handlerFunc: (context, params) {
      return KeyGame();
    }));
    // 练习页面
    router.define(book, handler: Handler(handlerFunc: (context, params) {
      return BookPage();
    }));
    // 数字计数器动画
    router.define(numCounter, handler: Handler(handlerFunc: (context, params) {
      return NumAnimate();
    }));
    router.define(testPage, handler: Handler(handlerFunc: (context, params) {
      return TestPage();
    }));
    router.define(rotatePage, handler: Handler(handlerFunc: (context, params) {
      return RotatePage();
    }));
    router.define(breathePage, handler: Handler(handlerFunc: (context, params) {
      return BreathePage();
    }));
    router.define(snowPage, handler: Handler(handlerFunc: (context, params) {
      return SnowPage();
    }));
    // 数据库
    router.define(dbpage,
        handler: Handler(handlerFunc: (_, __) => const DbPage()));
    router.define(p5Page, handler: Handler(handlerFunc: (context, params) {
      return P5Page();
    }));
    router.define(aePage, handler: Handler(handlerFunc: (context, params) {
      return AePage();
    }));
  }

  static void configureRoutes() {
    router.notFoundHandler =
        Handler(handlerFunc: (context, Map<String, List<String>> params) {
      // print('404');
      // print(params);
      return;
    });
    _initRouter();
  }
}
